<?php
#### MANAGEMENT HEADER #####################################################
function management_header() {
	$base =& Base::getInstance();

	if ($handle = opendir('modules')) {
	    while (false !== ($file = readdir($handle))) {
	        if (file_exists('modules/'.$file.'/menu_entry.inc')) {
	        	include ('modules/'.$file.'/menu_entry.inc');
				$links[] = array('name' => $name, 'image' => $image, 'url' => 'manage/'.$file);
				unset($name, $image);
	        }
	    }
	    closedir($handle);
	}

	@sort($links);

	// Reverse array and insert Home at the bottom
	$links = @array_reverse($links);
	$links[] = array('name' => 'Home', 'url' => 'manage', 'image' => $base->icon['home']);

	// Reverse array so Home is at the top and insert Log Out at the bottom
	$links = array_reverse($links);
	$links[] = array('name' => 'Log Out', 'url' => 'logout', 'image' => $base->icon['logout']);

	$menu = NULL;
	foreach ($links as $link) {
		$tpl = new template('management_menu_links', 'common');
		$tpl->assign('NAME', $link['name']);
		$tpl->assign('URL', $link['url']);
		$tpl->assign('IMAGE', $link['image']);
		$menu = $menu.$tpl->output();
	}

	$title = $base->icon['admin'].' '.'Management Menu';
	$body = '<ul class="menu">'.$menu.'</ul><div class="spacer"></div>';
	return box($title, $body);
}
?>